@extends('newAdmin.layout.main')

@section('content')
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">实名认证</a>
            <a><cite>企业认证</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ 刷新</i>
        </a>
    </div>
    <div class="x-body">
        <table class="layui-table">
            <thead>
            <tr>
                <th>ID</th>
                <th>用户名</th>
                <th>企业名称</th>
                <th>手机</th>
                <th>社会统一编码</th>
                <th>法定代表人</th>
                <th>省/市/区</th>
                <th>详细信息</th>
                <th>企业邮箱</th>
                <th>车辆数量</th>
                <th>营业执照</th>
                <th>法人身份证(正)</th>
                <th>法人身份证(反)</th>
                <th>申请认证时间</th>
                <th>操作</th>
            </thead>
            <tbody>
            @foreach($list as $enterprise)
                <tr>
                    <td>{{$enterprise->id}}</td>
                    <td>{{$enterprise->name}}</td>
                    <td>{{$enterprise->enterprise_info->name}}</td>
                    <td>{{$enterprise->phone}}</td>
                    <td>{{$enterprise->enterprise_info->social_unified_coding}}</td>
                    <td>{{$enterprise->enterprise_info->legal_person}}</td>
                    <td>{{$enterprise->enterprise_info->province}}</td>
                    <td>{{$enterprise->enterprise_info->address}}</td>
                    <td>{{$enterprise->enterprise_info->mail}}</td>
                    <td>{{$enterprise->enterprise_info->number}}</td>
                    <td><img src="{{asset('')}}/{{$enterprise->enterprise_info->business_license}}" alt=""></td>
                    <td><img src="{{asset('')}}/{{$enterprise->enterprise_info->front_id_photo}}" alt=""></td>
                    <td><img src="{{asset('')}}/{{$enterprise->enterprise_info->back_id_photo}}" alt=""></td>
                    <td>{{$enterprise->enterprise_info->create_time}}</td>
                    <td class="td-manage">
                        <a title="通过" onclick="enable(this, '{{$enterprise->id}}')" href="javascript:;">
                            <i class="layui-icon font-24">&#x1005;</i>
                        </a>
                        <a title="拒绝" onclick="disable(this, '{{$enterprise->id}}')" href="javascript:;">
                            <i class="layui-icon font-24">&#x1007;</i>
                        </a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        <div class="page">
            {{$list->links()}}
        </div>
    </div>
    <script>
        /*认证-拒绝*/
        function disable(obj, id){
            layer.confirm('确认要拒绝吗？',function(){
                //发异步删除数据
                $.ajax({
                    url: '{{url("backstage/user/ident/audit")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {"id": id, "status": 2, "_token": "{{csrf_token()}}", "type": "enterprise"},
                    success: function (result) {
                        if (result.status === 0) {
                            $(obj).parents("tr").remove();
                            layer.msg('已拒绝!', {icon: 1, time: 1000});
                            location.href = '{{url("backstage/user/ident/enterprise")}}';
                            return false;
                        }
                        layer.msg(result.msg);
                        return false;
                    },
                    error: function () {
                        layer.msg('禁用失败，请重试！');
                        return false;
                    }
                });
                return false;
            });
        }

        /*认证-通过*/
        function enable(obj, id){
            layer.confirm('确认要通过吗？',function(){
                //发异步删除数据
                $.ajax({
                    url: '{{url("backstage/user/ident/audit")}}',
                    type: 'post',
                    dataType: 'json',
                    data: {"id": id, "status": 1, "_token": "{{csrf_token()}}", "type": "enterprise"},
                    success: function (result) {
                        if (result.status === 0) {
                            $(obj).parents("tr").remove();
                            layer.msg('已通过!', {icon: 1, time: 1000});
                            location.href = '{{url("backstage/user/ident/enterprise")}}';
                            return false;
                        }
                        layer.msg(result.msg);
                        return false;
                    },
                    error: function () {
                        layer.msg('启用失败，请重试！');
                        return false;
                    }
                });
                return false;
            });
        }
    </script>
@endsection
